﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;

using RedPanda.MusicPlayer.DataModel;

namespace RedPanda.MusicPlayer.ViewModel
{
    /// <summary>
    /// 该类是绑定到UI的当前播放音乐文件;
    /// </summary>
    public class AudioFileViewModel :INotifyPropertyChanged
    {
        #region filed
        private AudioFile audioFile;
        private double playedTime;
        #endregion

        #region Constructor
        public AudioFileViewModel(AudioFile af)
        {
            this.audioFile = af;
            this.playedTime = 0;
        }
        #endregion

        #region Property

        public string Artist
        {
            get
            {
                return audioFile.Artist;
            }
            set
            {
                audioFile.Artist = value;
            }
        }

        public string Title
        {
            get
            {
                return audioFile.Title;
            }
            set
            {
                if (!(audioFile.Title.Equals(value)))
                {
                    audioFile.Title = value;
                    this.Notify("Title");
                }
            }
        }

        public string Location
        {
            get
            {
                return audioFile.Location;
            }
            set
            {
                this.audioFile.Location = value;
                this.Notify("Location");
            }
        }

        public string Album
        {
            get
            {
                return audioFile.Album;
            }
            set
            {
                if (!(audioFile.Album.Equals(value)))
                {
                    audioFile.Album = value;
                    this.Notify("Album");
                }
            }
        }

        public string Year
        {
            get
            {
                return audioFile.Year;
            }
            set
            {
                audioFile.Year = value;
                this.Notify("Year");
            }
        }

        public string Genre
        {
            get
            {
                return audioFile.Genre;
            }
            set
            {
                audioFile.Genre = value;
                this.Notify("Genre");
            }
        }

        public double Duration
        {
            get
            {
                return audioFile.Duration;
            }
            set
            {
                audioFile.Duration = value;
                this.Notify("Duration");
            }
        }

        public double PlayedTime
        {
            get
            {
                return playedTime;
            }
            set
            {
                playedTime = value;
                this.Notify("PlayedTime");
            }
        }

        #endregion

        #region event
        public  event PropertyChangedEventHandler PropertyChanged;
        #endregion

        #region event Handler
        private void Notify(string propertyName)
        {
            if (this.PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }
        #endregion
    }
}
